package com.bbcare.comm;

import java.sql.Connection;
import java.sql.SQLException;

import com.mchange.v2.c3p0.ComboPooledDataSource;

/*
 * @name:         手动获取数据库连接
 * @author:       DemonLee
 * @createTime:   2017.4.24
 * @description:  手动获取数据库连接
 * @modify:
 * 
 */

public class JdbcUtil {
    private static Connection conn;

    public static Connection getConnection(ComboPooledDataSource ds) {
        try {
            conn = ds.getConnection();
        } catch (SQLException e) {
            e.printStackTrace();
            throw (new AppException("112233", "获取数据库连接失败!"));
        }
        return conn;
    }

    public static void returnConnection(Connection conn) {
        try {
            if (null != conn) {
                conn.close();
            }
        } catch (SQLException e) {
            e.printStackTrace();
            throw (new AppException("112233", "关闭数据库连接失败!"));
        }
        return;
    }

}
